-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(gatsby-plugin-google-tagmanager): GDPR consent + default options #11379
Conversation
This comes with object destructuring of pluginOptions to enable default values.
Thanks for creating this PR, I'm just not sure this is a good fix for gdpr & googletagmanager. Googletag manager doesn't break GDPR regulations. It's what googletag is configured to do, that might have issues with GPDR. Adding these gdpr variables in my opinion isn't a correct fix and might make this plugin a bit more complicated to use. The correct fix is to actually push something on your DataLayer that tells gtm to load or not load scripts. If this is hard to do I'm ok with creating a shouldLoad option that has a function to skip loading which is more general approach than just checking a global variable. What do you think? (also want to involve @gatsbyjs/core into this discussion) |
Hm, I tried the approach of using To control this you would need to add a script (for browser) + the |
Yes, that's true. I just don't think |
The Since the user needs to agree in the browser, this would be no solution I think. As you said, We could add an option that takes a function which will be injected before the GTM code and allows for early |
I'll make 2 examples one with dataLayer and one with the shouldLoad function. I was thinking a function that's ran inside the browser. |
@cardiv would something like this work? |
Nice work @wardpeet, thank you! I am a bit confused about two code parts but this could handle some more use cases. |
@cardiv could you test if it works now. I updated the test so we catch my errors 👍 |
@cardiv ping :) I would love to get this merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to work! Function is being omitted though but the issue is not part of this PR
There is some cleanup that needs to be done before merging. @wardpeet will address this as soon as he has time. Thank you for your patience! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's finally ship this! 🚢
Description
As of the GDPR it is a best practice to gather the user agreement on setting cookies and/or enabling tracking scripts. It's the developers responsibility to enable tracking/cookies on user consent and to remove cookies if the user declines afterwards.
But, we should give the developers options to make that possible and their jobs easier.
This PR allows two more options:
gdpr
to disable Google Tag Manager on page load. Set tofalse
by default.gdprConsent
for a global variable (insidewindow
) that holds the users consent. Results inwindow['gdprConsent']
by default.gdpr
could be set by an environment variable, that is set depending on the users location (EU or not) and controlled by the ADN.Again, it is the developers responsibility to gather the consent and set
window[gdprConsent]
. This value should come from a cookie and I plan to develop a plugin/component that enables the user to agree, sets both the cookie and variable, executes optional functions and renders blocked children.The code is now wrapped inside a
gtmCode()
function that is needed to enable Google Tag Manager without reloading the page.Object destructuring
This feature introduces default options by destructuring the options object. It seemed appropriate to add this with the GDPR feature.
The default value of
includeInDevelopment
(README) is now set too.Related Issues
@sebastienfi uses GA (comment) in a similar way, but with a
window.gdpr-agreed
variable.